Trò chơi Halloween vui nhộn trong UNITY Engine
10.799 lượt xem;
- SpawnDestruction.cs
- DestructionScripts /
- Scripts /
- Assets /
- project /
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class SpawnDestruction : MonoBehaviour {
6
7 public GameObject[] destruction;
8
9 public Transform spawnPoint;
10
11 public int spawnCount;
12
13 public float startTime, waveTime, spawnTime;
14
15 private float min = 2.5f;
16 private float max = 3.6f;
17
18 void Start () {
19 StartCoroutine(Destruction());
20 }
21
22 void Update () {
23
24 }
25
26 IEnumerator Destruction() {
27 yield return new WaitForSeconds(startTime);
28 while (true)
29 {
30 for (int i = 0; i < spawnCount; i++)
31 {
32 transform.position = new Vector3(spawnPoint.position.x, Random.Range(min, max), spawnPoint.position.y);
33 Quaternion spawnRotation = Quaternion.identity;
34 int randomNumber = Random.Range(0, 2);
35
36 Instantiate(destruction[randomNumber], transform.position, spawnRotation);
37
38 yield return new WaitForSeconds(spawnTime);
39 }
40
41 yield return new WaitForSeconds(waveTime);
42 }
43 }
44 }
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class SpawnDestruction : MonoBehaviour {
6
7 public GameObject[] destruction;
8
9 public Transform spawnPoint;
10
11 public int spawnCount;
12
13 public float startTime, waveTime, spawnTime;
14
15 private float min = 2.5f;
16 private float max = 3.6f;
17
18 void Start () {
19 StartCoroutine(Destruction());
20 }
21
22 void Update () {
23
24 }
25
26 IEnumerator Destruction() {
27 yield return new WaitForSeconds(startTime);
28 while (true)
29 {
30 for (int i = 0; i < spawnCount; i++)
31 {
32 transform.position = new Vector3(spawnPoint.position.x, Random.Range(min, max), spawnPoint.position.y);
33 Quaternion spawnRotation = Quaternion.identity;
34 int randomNumber = Random.Range(0, 2);
35
36 Instantiate(destruction[randomNumber], transform.position, spawnRotation);
37
38 yield return new WaitForSeconds(spawnTime);
39 }
40
41 yield return new WaitForSeconds(waveTime);
42 }
43 }
44 }